package raochang.enums;

/**
 *
 * 阅读状态枚举
 */
public enum ReaderStateEnum {
    /**
     *
     * 删除
     */
    DELETED(3, "删除"),
    /**
     * 过期
     */
    EXPIRED(2, "过期"),
    /**
     * 注销
     */
    LOGOUT(1, "注销"),
    /**
     * 正常
     */
    NORMAL(0, "正常");

    private int code;
    private String name;

    ReaderStateEnum(int code, String name) {
        this.code = code;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public static String getNameByCode(int code) {
        for (ReaderStateEnum state : values()) {
            if (state.getCode() == code) {
                return state.getName();
            }
        }
        throw new IllegalArgumentException("Invalid code: " + code);
    }

    public static int getCodeByName(String name) {
        for (ReaderStateEnum state : values()) {
            if (state.getName().equals(name)) {
                return state.getCode();
            }
        }
        throw new IllegalArgumentException("Invalid name: " + name);
    }
}
